package com.example.diggold;

import android.R.drawable;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

public class change_image extends Activity{
	
	//
	
	final Context context = this;
	private Button button;
	private EditText result;
	//
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game_room);
        this.addListenerOnButton();
    }

	private void addListenerOnButton() {
		ImageButton image_star = (ImageButton) findViewById(R.id.imageButton1);
		ImageButton image_aa = (ImageButton) findViewById(R.id.imageButton2);
			
		image_star.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				
				//ImageView btn = (ImageView)findViewById(R.id.ImageView02);
				//btn.setImageResource(drawable.btn_star_big_off);
				
				//---
				// get prompts.xml view
				LayoutInflater li = LayoutInflater.from(context);
				View promptsView = li.inflate(R.layout.prompts, null);
 
				AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
 
				// set prompts.xml to alertdialog builder
				alertDialogBuilder.setView(promptsView);
 
				final EditText userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput);
 
				// set dialog message
				alertDialogBuilder.setCancelable(false).setPositiveButton("OK",new DialogInterface.OnClickListener() 
				{
					    public void onClick(DialogInterface dialog,int id) {
						
					    String src = "ImageView0" + userInput.getText();
					    
						Toast.makeText(change_image.this,src, Toast.LENGTH_SHORT).show();

					    int resID = getResources().getIdentifier(src, "id", getPackageName());
						ImageView btn = (ImageView)findViewById(resID);
						btn.setImageResource(drawable.btn_star_big_off);
						
					    }
				})
				.setNegativeButton("Cancel",new DialogInterface.OnClickListener() 
				{
					    public void onClick(DialogInterface dialog,int id) {
						dialog.cancel();
					    }
				});
 
				// create alert dialog
				AlertDialog alertDialog = alertDialogBuilder.create();
 
				// show it
				alertDialog.show();
				//-----
				
			}});
		
		image_aa.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				
				LayoutInflater li = LayoutInflater.from(context);
				View promptsView = li.inflate(R.layout.prompts, null);
 
				AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
 
				alertDialogBuilder.setView(promptsView);
 
				final EditText userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput);
 
				alertDialogBuilder.setCancelable(false).setPositiveButton("OK",new DialogInterface.OnClickListener() 
				{
					    public void onClick(DialogInterface dialog,int id) {
						
					    String src = "ImageView0" + userInput.getText();
					    
						Toast.makeText(change_image.this,src, Toast.LENGTH_SHORT).show();

					    int resID = getResources().getIdentifier(src, "id", getPackageName());
						ImageView btn = (ImageView)findViewById(resID);
						
						btn.setImageResource(drawable.btn_default_small);
						
					    }
				})
				.setNegativeButton("Cancel",new DialogInterface.OnClickListener() 
				{
					    public void onClick(DialogInterface dialog,int id) {
						dialog.cancel();
					    }
				});
 
				// create alert dialog
				AlertDialog alertDialog = alertDialogBuilder.create();
 
				// show it
				alertDialog.show();
				//-----
				
			}});
		
	}

}
